<template>
	<view>
<!-- 		<view class="example-body">
			<view class="item">
				<view class="item-title">手机号</view>
				<input v-model="tel" maxlength="30" :class="['uni-input', {activeipt:activeArr[0]}]" type="text" @focus="onfocus(0)"/>
			</view>
			<view class="item">
				<view class="item-title">邮箱</view>
				<input v-model="email" maxlength="30" :class="['uni-input', {activeipt:activeArr[1]}]"  type="text" @focus="onfocus(1)"/>
			</view>
		</view>
		<view class="submit">
			<button type="primary" size="mini" @click="submit">保存</button>
		</view> -->
	</view>
</template>

<script>
	export default {
		data() {
			return {
				activeArr:[false,false],
				// 15607106315
				tel:'',
				email:''
			}
		},
		onLoad(option) {
			this.tel=JSON.parse(option.homeinfo).tel
			this.email=JSON.parse(option.homeinfo).email
		},
		methods: {
			onfocus(val){
				this.activeArr=[false,false]
				this.activeArr[val]=true
			},
			async submit(){
				var reg = /^1[3|4|5|8][0-9]\d{4,8}$/;
				var reg1 =/^[\w\-]+@[a-zA-Z\d\-]+(\.[a-zA-Z]{2,8}){1,2}$/ig
				if (this.tel!==''&&!reg.test(this.tel)) {
					uni.showToast({ title: '手机号输入有误!', icon:"none" })
					return
				}
				if (this.email!==''&&!reg1.test(this.email)) {
					uni.showToast({ title: '邮箱输入有误!', icon:"none" })
					return
				}
				let [err,res]=await this.$http.post("/authentication",{
					user: uni.getStorageSync('name'),
					tel:this.tel,
					email:this.email
				})
				// 请求错误处理
				if (!this.$http.errorCheck(err,res)) return
				if(res.data==1){
					uni.showToast({ title: '账号绑定成功！', icon:"success"})
					setTimeout(()=>{
						uni.navigateBack({
							delta: 1
						});
					},1500)
				}else{
					uni.showToast({ title: '身份认证失败！', icon:"none" })
				}
			}
		}
	}
</script>

<style lang="less" scoped>
.uni-view{
	justify-content: center;
}
.item{
	display: flex;
	justify-content: center;
	margin-right: 40upx;
	.item-title{
		flex-basis: 150upx;
		display: flex;
		align-items: center;
		padding-left: 40upx;
	}
	.uni-input{
		flex: 1;
	}
}
.uni-input {
	border-bottom: 1px solid #ececec;
}
.activeipt {
	border-bottom: 1px solid #26ca0d;
}
.note{
	font-size: 35upx;
	padding-left: 40upx;
	margin-top: 20upx;
	color: #999999;
}
.submit{
	display: flex;
	justify-content: center;
	margin-top: 20upx;
	uni-button[type=primary]{
		background-color: #26ca0d!important;
	}
}
</style>
